CMAKE_MINIMUM_REQUIRED(VERSION 3.10)

PROJECT(TRACER)

FILE(GLOB_RECURSE TRACER_SRC
		"${PROJECT_SOURCE_DIR}/src/*.cpp"
		"${PROJECT_SOURCE_DIR}/src/*.h"
		"${PROJECT_SOURCE_DIR}/include/agz/tracer/*.h"
		"${PROJECT_SOURCE_DIR}/include/agz/tracer/*.inl")

ADD_LIBRARY(Tracer STATIC ${TRACER_SRC})

FOREACH(_SRC IN ITEMS ${TRACER_SRC})
    GET_FILENAME_COMPONENT(TRACER_SRC "${_SRC}" PATH)
    STRING(REPLACE "${PROJECT_SOURCE_DIR}/include/agz/tracer" "include" _GRP_PATH "${TRACER_SRC}")
    STRING(REPLACE "${PROJECT_SOURCE_DIR}/src" "src" _GRP_PATH "${_GRP_PATH}")
    STRING(REPLACE "/" "\\" _GRP_PATH "${_GRP_PATH}")
    SOURCE_GROUP("${_GRP_PATH}" FILES "${_SRC}")
ENDFOREACH()

SET_PROPERTY(TARGET Tracer PROPERTY CXX_STANDARD 17)
SET_PROPERTY(TARGET Tracer PROPERTY CXX_STANDARD_REQUIRED ON)

IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
	IF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
		SET(LINKER_FLAGS "-lc++fs -ldl -pthread")
	ELSE()
		SET(LINKER_FLAG "-lstdc++fs -ldl -pthread")
	ENDIF()
ELSEIF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
    SET(LINKER_FLAGS "-lstdc++fs -ldl -pthread")
ENDIF()

SET(Tracer_INCLUDE_DIRS
	"${PROJECT_SOURCE_DIR}/include/"
	"${AGZUtils_INCLUDE_DIRS}"
	"${MISC_INCLUDE_DIRS}"
	"${EMBREE_INCLUDE_DIRS}")

IF(USE_EMBREE)
	SET(Tracer_INCLUDE_DIRS ${Tracer_INCLUDE_DIRS} ${EMBREE_INCLUDE_DIRS})
	SET(Tracer_EMBREE_LIB ${EMBREE_LIBRARY})
	TARGET_COMPILE_DEFINITIONS(Tracer PUBLIC USE_EMBREE)
ENDIF()

IF(USE_OIDN)
	SET(Tracer_OIDN_LIB OpenImageDenoise)
ENDIF()
TARGET_INCLUDE_DIRECTORIES(Tracer PUBLIC ${Tracer_INCLUDE_DIRS})

TARGET_LINK_LIBRARIES(Tracer PUBLIC AGZUtils spdlog ${Tracer_OIDN_LIB} ${Tracer_EMBREE_LIB} ${LINKER_FLAGS})
